import pandas as pd
import numpy as np
import seaborn as sns
import plotly.graph_objects as go
import plotly.express as px
!pip install plotly
Requirement already satisfied: plotly in /Users/salimwid/opt/anaconda3/lib/python3.8/site-packages (5.4.0)
Requirement already satisfied: six in /Users/salimwid/opt/anaconda3/lib/python3.8/site-packages (from plotly) (1.15.0)
Requirement already satisfied: tenacity>=6.2.0 in /Users/salimwid/opt/anaconda3/lib/python3.8/site-packages (from plotly) (8.0.1)
WARNING: You are using pip version 21.3; however, version 21.3.1 is available.
You should consider upgrading via the '/Users/salimwid/opt/anaconda3/bin/python -m pip install --upgrade pip' command.
df_final = pd.read_csv('final_data_cleaned_17nov.csv', index_col = [0])
df_final.dropna(inplace=True)
df_final.loc[df_final['Body Mass Index (kg/m**2)'] > 30 , 'bmi_group'] = 'Obese'
df_final.loc[df_final['Body Mass Index (kg/m**2)'] < 30 , 'bmi_group'] = 'Overweight'
df_final.loc[df_final['Body Mass Index (kg/m**2)'] < 25 , 'bmi_group'] = 'Healthy'
df_final.loc[df_final['Body Mass Index (kg/m**2)'] <= 18.5 , 'bmi_group'] = 'Underweight'
df_final.loc[df_final['AgeYears'] > 60 , 'age_group'] = '> 60 Years'
df_final.loc[df_final['AgeYears'] < 60 , 'age_group'] = '51 - 60 Years'
df_final.loc[df_final['AgeYears'] < 50 , 'age_group'] = '41 - 50 Years'
df_final.loc[df_final['AgeYears'] < 40 , 'age_group'] = '31 - 40 Years'
df_final.loc[df_final['AgeYears'] < 30 , 'age_group'] = '21 - 30 Years'
df_final.loc[df_final['AgeYears'] < 20 , 'age_group'] = '11 - 20 Years'
df_final.loc[df_final['AgeYears'] < 10 , 'age_group'] = '0 - 10 Years'
print(df_final.loc[df_final['bmi_group'] == 'Obese'].shape[0]/8971*100)
print(df_final.loc[df_final['bmi_group'] == 'Overweight'].shape[0]/8971*100)
print(df_final.shape)
30.97759447107346 29.874038568721435 (8971, 85)
fig = go.Figure(data=[
go.Bar(name='Diabetic', x=df_final['age_group'], y=df_final['is_diabetic'], marker = {'color': 'red'}),
go.Bar(name='High Risk', x=df_final['age_group'], y=df_final['high_risk'], marker = {'color': 'blue'}),
])
# Change the bar mode
fig.update_traces(dict(marker_line_width=0))
fig.update_layout(barmode='group', title="Count of Diabetic and High Risk Individuals per Age Group", yaxis_title="Count of Diabetic & High Risk Individuals", xaxis_title="Age Group")
fig.update_xaxes(categoryorder='category ascending')
fig.show()
df = px.data.tips()
fig = px.bar(df_final, x="bmi_group", y='is_diabetic',
category_orders={"bmi_group": ["Underweight", "Healthy", "Overweight", "Obese"]})
fig.update_traces(dict(marker_line_width=0), marker= {'color' : 'blue'})
fig.update_layout(title="Count of Individuals in each BMI Group", yaxis_title="Count of Individuals", xaxis_title="BMI Group")
fig.show()
df = px.data.tips()
fig = px.bar(df_final, x="bmi_group",
category_orders={"bmi_group": ["Underweight", "Healthy", "Overweight", "Obese"]})
fig.update_traces(dict(marker_line_width=0), marker= {'color' : '#42f5a4'})
fig.update_layout(title="Count of Individuals in each BMI Group", yaxis_title="Count of Individuals", xaxis_title="BMI Group")
fig.show()
100-43.61604689503572
56.38395310496428
df = df_final[df_final['bmi_group'].isin(['Obese', 'Overweight'])]
fig = px.pie(df, values=[0.436, 0.564], names=['Diabetic', 'Non-Diabetic'])
fig.update_layout(title="% of Diabetic Individuals among Overweight & Obese Population")
fig.show()
s1 = df_final[df_final['is_diabetic'] == 1].sample(896).index
s0 = df_final[df_final['is_diabetic'] == 0].sample(1796).index
df = df_final.loc[s0.union(s1)]
#True Negative
print('True Negative: {}'.format(df[(df['high_risk'] == 0) & (df['is_diabetic'] == 0)].shape[0]))
#True Positive
print('True Positive: {}'.format(df[(df['high_risk'] == 1) & (df['is_diabetic'] == 1)].shape[0]))
#False Negative
print('False Negative: {}'.format(df[(df['high_risk'] == 0) & (df['is_diabetic'] == 1)].shape[0]))
#False Positive
print('False Positive: {}'.format(df[(df['high_risk'] == 1) & (df['is_diabetic'] == 0)].shape[0]))
True Negative: 1655 True Positive: 213 False Negative: 683 False Positive: 141